package com.example.plat.controller;

import com.example.plat.enity.User;
import com.example.plat.exception.UserException;
import com.example.plat.security.JwtTokenUtil;
import com.example.plat.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@Api(description = "用户管理")
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    UserService service;

    @ApiOperation("根据用户名查询用户")
    @GetMapping("/{userName}")
    public ResponseEntity<User> findUser(@PathVariable String userName){
        User user = service.findUser(userName);
        return ResponseEntity.ok(user);
    }

    @ApiOperation("修改用户")
    @PostMapping
    public ResponseEntity<User> changeUser(@RequestBody User user) throws UserException {
        User newUser = service.changeUser(user);
        return ResponseEntity.ok(newUser);
    }
}
